#! /usr/bin/env python
# -*- coding: utf-8 -*-

# *************************************************************
#     Filename @  getattr.py
#       Author @  Huoty
#  Create date @  2016-07-02 19:34:05
#  Description @  
# *************************************************************

class Foo(object):
    def __init__(self):
        pass

    def __getattr__(self, key):
        print("-" * 100, key)
        try:
            return self.__dict__[key]
        except KeyError:
            return None

    def __setattr__(self, key, value):
        self.__dict__[key] = value

    def __delattr__(self, key):
        try:
            del self.__dict__[key]
        except KeyError:
            return None


class Foo2(Foo):

    def test(self):
        print(self.bar)


class Foo3(object):

    def __init__(self):
        self.bar = 10


Foo4 = type("Foo4", (Foo3, Foo), {})


# Script starts from here

if __name__ == "__main__":
    f = Foo()
    print(f.bar)
    f.bar = 10
    print(f.bar)
    del f.bar

    f2 = Foo2()
    f2.test()

    f4 = Foo4()
    print(f4.tar)
